home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
comm2
/
alist.lha
/
src
/
aldef.e
< prev
next >
Wrap
Text File
|
1995-11-08
|
3KB
|
117 lines
/* ALDef.M */
OPT MODULE
OPT EXPORT
/* AList definitions and structures file */
MODULE 'exec/nodes'
MODULE 'exec/ports'
OBJECT almsg /* AList Message */
mn:mn
command:LONG
field1:LONG
field2:LONG
arg:LONG
ENDOBJECT
/* Commands (ALM = AList Message) */
ENUM ALM_QUIT, /* Shut down */
ALM_SEND, /* Post a message to a list */
ALM_ADDR, /* Parse an address/name & return the results */
ALM_NOOP /* Do-nothing command */
/* For the barnacle_start() and _end() and for use as the replyport for barnacle_put_msg() */
/* Just don't use it in barnacle_put_msg() without first calling barnacle_start()! (: */
DEF alist_replyport:PTR TO mp
/*
* Easiest way to start up a message port specific for the barnacle_put_msg()
* function below.
* WARNING: ONLY CALL THIS FUNCTION IF alist_replyport DOES *NOT* POINT TO A VALID PORT!
* You should only need to call this once, at the start of your program.
* You should also check to ensure (alist_replyport <> NIL) before going on...
*/
PROC barnacle_start()
alist_replyport := CreateMsgPort() /* A happy little OS 2.0+ function. */
IF (alist_replyport) THEN alist_replyport.ln.name := NIL /* A little insurance... */
ENDPROC
/*
* For use in conjunction with barnacle_start()
*
* Make sure to call this only if alist_replyport is a valid port.
* Best way to do this is to call it only once, at the end of your program.
*/
PROC barnacle_end()
DEF tmp:PTR TO mn
IF (alist_replyport)
/* Use my nice little routine to kill a port */
IF (alist_replyport.ln.name) THEN RemPort (alist_replyport)
Forbid ()
WHILE (tmp := GetMsg (alist_replyport))
Remove (tmp)
IF (tmp.replyport)
Permit()
ReplyMsg (tmp)
Forbid()
ENDIF
ENDWHILE
DeleteMsgPort (alist_replyport)
Permit()
ENDIF
alist_replyport := NIL
ENDPROC
/*
* Procedure for our barnacles to use... (:
*
* Note that 'arg' isn't in the same place it is in the OBJECT...
* Returns -1 (TRUE) if it can't send the message
*
* Note that 'rp' is required! If we don't wait for the reply, and
* deallocate the message, it won't get through.
* Also note that the 'rp' message list must be empty, or we'll
* eat a waiting message and free up the message which was sent.
*
* Easiest way to use this func is to call barnacle_start() at the
* start of your program, then pass in NIL as the 'rp', which will
* cause it to use the allocated port. Be sure to call barnacle_end()
* before you quit though...
*/
PROC barnacle_put_msg (rp, cmd, arg=NIL, field1=NIL, field2=NIL)
DEF msg:PTR TO almsg, tmp, tmp2
IF (rp = NIL) THEN rp := alist_replyport
NEW msg
msg.mn.replyport := rp
msg.mn.length := SIZEOF almsg
msg.command := cmd
msg.field1 := field1
msg.field2 := field2
msg.arg := arg
Forbid ()
tmp := FindPort ('AList')
IF (tmp)
PutMsg (tmp, msg)
ENDIF
Permit ()
tmp2 := NIL
IF (tmp) THEN tmp2 := WaitPort (rp)
IF (tmp2) THEN Remove (tmp2)
END msg
ENDPROC (tmp = FALSE)